/* 
 * @moduleName: TransFormSelectUtil.js
 * @Desc: 辅助函数 防止后期antd更新select的类型过多 造成单文件逻辑复杂 进行二次抽离
 * @Author: djkloop 
 * @Date: 2017-11-30 11:21:20 
 * @Last Modified by: djkloop
 * @Last Modified time: 2017-12-12 02:14:15
 */
import React from 'react'
import {Select} from 'antd'
import colUtil from './ColWrapperUtil';
const Option = Select.Option;

export default {
  transformSelect(field,type) {
    let _rules = field.dateRules && type === 'single' ? field.dateRules.rules : [];
    const options = [];
    field.options.forEach((option,index) => {
      options.push(<Option key={index} value={option.key}>{option.value}</Option>);
    });

    return colUtil.colWrapper((getFieldDecorator, forUpdate) => getFieldDecorator(field.key, {rules:_rules,initialValue: forUpdate ? undefined : field.defaultValue})(
      <Select placeholder={field.placeholder || '请选择'} size="default">
        {options}
      </Select>
    ), field);
  }
}
